home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1043 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.4 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: Martin Aupperle <100754.2730@CompuServe.COM>
  3. Newsgroups: comp.std.c++
  4. Subject: Ambiguity when overloading operators
  5. Date: 11 Apr 1996 23:50:24 GMT
  6. Organization: ?
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <960411233436_100754.2730_GHV68-1@CompuServe.COM>
  9. NNTP-Posting-Host: taumet.eng.sun.com
  10. Content-Length: 629
  11. X-Lines: 31
  12. Originator: clamage@taumet
  13.  
  14. If I define
  15.  
  16.   struct  X {
  17.  
  18.     X( int );
  19.     operator const char* () const;
  20.  
  21.     /* other members */
  22.     };
  23.  
  24.   X& operator + ( const X&, const X& );
  25.  
  26. I cannot say 
  27.  
  28.   X x1( 5 );
  29.   X x2 = x1+3;  // ambiguous
  30.  
  31. Borland BC4.5 says that x1+3 is ambiguous. I know that it can
  32. 1. convert 3 to an X and call operator + ( const X&, constX& )
  33. 2. convert x1 to a const char* and do pointer arithmetics. 
  34.  
  35. Is the compiler right? I have in mind that a conversion towards a user defined
  36. type has precedence over the conversion to a fundamental type. So choice (1)
  37. should be right and it shoud not be ambiguous. 
  38.  
  39. Am I correct?
  40. Martin
  41.  
  42.  
  43.  
  44. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  45. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  46. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  47. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  48. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  49.